﻿@{
    ViewBag.Title = "SetRole";
    Layout = "~/Views/Shared/_LayoutEdit.cshtml";
}

<ul id="treeRoleNodes" class="ztree lileft"></ul>


<div class="clearfix"></div>


<script>
    var setting = {
        check: {
            enable: true,
            chkStyle: "checkbox",
            chkboxType: { "Y": "ps", "N": "ps" }
        }
    };

    $(document).ready(function () {
        $.fn.zTree.init($("#treeRoleNodes"), setting, $.parseJSON('@Html.Raw(ViewBag.Nodes)'));
    });

    function SaveRoleNodes(callback) {
        var treeObj = $.fn.zTree.getZTreeObj("treeRoleNodes");
        var nodes = treeObj.getCheckedNodes(true);//选中的数据

        var ids = "";
        for (var i = 0; i < nodes.length; i++) {
            ids += nodes[i].id + ",";
        }

        console.log(ids);

        $.ajaxC({
            url: "@Url.Action("SetRole")",
            data: { id: "@ViewBag.id", ids: ids },
            success: function (data) {
                //成功
                msgsuc(data);
            },
            complete: function () {
                //完成之后的 判断回调函数是否存在
                if (callback) callback();
            }
        });

    }



</script>
